
package wiinf;

import javax.comm.*;

/**
 *
 * @author David Roos
 */
public class ServerlistenerSPPtest implements Runnable, SerialPortEventListener {
    private int tempData;

    public void serialEvent(SerialPortEvent e) {
        try {
            switch (e.getEventType()) {
                case SerialPortEvent.DATA_AVAILABLE: {
                    while (tempData != -1) {
                        //read data in
                    } //end while
//do something with the data
                } //end case
            } //end switch
        } catch (Exception p) {
            p.printStackTrace();
        }
    } //end serialEvent



    public void run() {
            try {
    SerialPort myPort = (SerialPort) CommPortIdentifier.getPortIdentifier("COM6").open("",0);
    myPort.setSerialPortParams(19200, SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
    myPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
    myPort.notifyOnDataAvailable(true);
    myPort.addEventListener(this);
    } catch(Exception e) {
            System.out.println(e);
    }
    }
}


